package cn.yunbamboos.rest.service.converter;

import cn.yunbamboos.exception.AppException;
import cn.yunbamboos.rest.service.ISessionContainer;
import cn.yunbamboos.rest.service.dto.in.BaseInDTO;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public abstract class RequestConverterInDTO {

    private static final Logger logger = LoggerFactory.getLogger(RequestConverterInDTO.class);

    private final List<MediaType> mediaTypes = new ArrayList<>();

    @Resource
    protected ISessionContainer sessionContainer;

    protected RequestConverterInDTO(MediaType... mediaTypes) {
        this.mediaTypes.addAll(Arrays.asList(mediaTypes));
    }

    public boolean supports(MediaType type) {
        boolean support = false;
        for (MediaType mediaType : mediaTypes) {
            if (mediaType.includes(type)) {
                support = true;
                break;
            }
        }
        return support;
    }

    public BaseInDTO converter(){
        throw AppException.c("Request Converter DTO is unrealized");
    }



}
